BITS 16               ; 16-bit real mode

;org 0x7c00            ; Load address of the bootloader
;这里去掉0x7c00后，所有标号计算的绝对地址就都是按0为基地址算的。

section .text
    start:
        mov ax, 0x07c0  ; Set up data segment to point to where we're loaded
        mov ds, ax
        mov es, ax       ; Extra segment too

        ; Print "Hello, Bochs!" using BIOS interrupt 0x10
        mov si, message   ; Load address of the message
        call print_string ; Call the print_string subroutine

        ; Hang (infinite loop)
        jmp $

    ; Subroutine to print a null-terminated string
    print_string:
        push ax           ; Save registers
        push bx
        push cx
        push dx

    .loop:
        mov al, [si]      ; Get character from string
        cmp al, 0         ; Check for null terminator
        je .done          ; If null, we're done

        mov ah, 0x0e      ; BIOS teletype function
        mov bh, 0x00      ; Page number (0)
        mov bl, 0x07      ; Text attribute (white on black)
        int 0x10          ; Call BIOS interrupt

        inc si            ; Move to next character
        jmp .loop         ; Continue looping

    .done:
        pop dx            ; Restore registers
        pop cx
        pop bx
        pop ax
        ret               ; Return from subroutine

    message db "Hello, Bochs!", 0  ; Null-terminated string

    ; Padding and magic number
    times 510 - ($ - $$) db 0      ; Pad to 510 bytes
    dw 0xaa55                     ; Boot sector signature
